/**
 * 
 */
package org.istt.service.impl;

import java.util.List;

import org.istt.dao.WorkflowDao;
import org.istt.domain.Workflow;
import org.istt.service.WorkflowManager;
import org.istt.web.helper.ExtendedPaginatedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Huy
 *
 */
@Service("workflowManager")
public class WorkflowManagerImpl extends ManagerImpl<Workflow, Long> implements WorkflowManager {
	
	/**
	 * @param WorkflowDao the WorkflowDao to set
	 */
	@Autowired
	public void setWorkflowDao(WorkflowDao dao) {
		this.dao = dao;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.istt.service.WorkflowManager#getWfpByWfId(java.lang.Long)
	 */
	@Override
	public List<Object[]> getWfpByWfId(Long workflowId) {
		return ((WorkflowDao)dao).getWfpByWfId(workflowId);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.istt.service.WorkflowManager#removeWorkflowProcess(java.lang.Long, java.lang.Long)
	 */
	@Override
	public void removeWorkflowProcess(Long workFlowId, Long processStatusId) {
		((WorkflowDao)dao).removeWorkflowProcess(workFlowId, processStatusId);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.istt.service.WorkflowManager#getMaxPosition(java.lang.Long)
	 */
	@Override
	public Integer getMaxPosition(Long workFlowId) {
		return ((WorkflowDao)dao).getMaxPosition(workFlowId);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.istt.service.WorkflowManager#isDeletable(java.lang.Long)
	 */
	@Override
	public boolean isDeletable(Long workflowId) {
		return ((WorkflowDao)dao).isDeletable(workflowId);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.istt.service.WorkflowManager#getTotalDayOfWork(java.lang.Long)
	 */
	@Override
	public Double getTotalDayOfWork(Long workflowId) {
		return ((WorkflowDao)dao).getTotalDayOfWork(workflowId);
	}

	@Override
	public ExtendedPaginatedList searchWf(String wfName,
			ExtendedPaginatedList paginatedList) {
		List<Workflow> results = ((WorkflowDao)dao).getWfByName(wfName, paginatedList
                .getFirstRecordIndex(), paginatedList.getPageSize(), paginatedList
                .getSortDirection(), paginatedList.getSortCriterion());
		
		paginatedList.setList(results);
        paginatedList.setTotalNumberOfRows(((WorkflowDao)dao).getWfRecordCountByName(wfName));
        
		return paginatedList;
	}

}
